﻿<%@ WebHandler Language="C#" Class="ItemHandler" %>

using System;
using System.Web;
using System.Web.SessionState;
using PaymentBLL;

public class ItemHandler : IHttpHandler, IReadOnlySessionState
{

    public void ProcessRequest(HttpContext context)
    {
        string type = context.Request.QueryString["t"] ?? string.Empty;

        switch (type)
        {
            case "GetListItemIn":
                GetListItemIn(context);
                break;
            case "GetListItemOut":
                GetListItemOut(context);
                break;  
        }
    }
    public void GetListItemIn(HttpContext context)
    {
        var ctr=new CtrItem();
        int currentPage = Convert.ToInt32(context.Request.QueryString["currentPage"] ?? "1");
        int pageSize = Convert.ToInt32(context.Request.QueryString["pageSize"] ?? "10");
        int paymentGateWayId = Convert.ToInt32(context.Request.QueryString["paymentGateWayId"] ?? "2");
        
        int? totalRecord = 0;
        var items = ctr.SelectItemInBy(paymentGateWayId, 1, currentPage, pageSize, ref totalRecord);
        string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(items);
        context.Response.ContentType = "application/json";
        context.Response.Write(jsonString);
    }
    public void GetListItemOut(HttpContext context)
    {
        var ctr = new CtrItem();
        int currentPage = Convert.ToInt32(context.Request.QueryString["currentPage"] ?? "1");
        int pageSize = Convert.ToInt32(context.Request.QueryString["pageSize"] ?? "10");
        int paymentGateWayId = Convert.ToInt32(context.Request.QueryString["paymentGateWayId"] ?? "2");

        int? totalRecord = 0;
        var items = ctr.SelectItemOutBy(paymentGateWayId, 1, currentPage, pageSize, ref totalRecord);
        string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(items);
        context.Response.ContentType = "application/json";
        context.Response.Write(jsonString);
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}